package cn.znzz.cjm.pet.service.impl;


import cn.znzz.cjm.basic.service.impl.BaseServiceImpl;
import cn.znzz.cjm.pet.domain.Pet;
import cn.znzz.cjm.pet.domain.PetDetail;
import cn.znzz.cjm.pet.mapper.PetDetailMapper;
import cn.znzz.cjm.pet.mapper.PetMapper;
import cn.znzz.cjm.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PetServiceImpl  extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void add(Pet pet) {
        //保存宠物信息
        petMapper.save(pet);
        //保存宠物基本信息
        PetDetail detail = pet.getDetail();
        if(detail !=null){
            detail.setPet_id(pet.getId());
            petDetailMapper.save(detail);
        }
    }

    @Override
    public void onSale(List<Long> ids) {
        Map<String,Object> map=new HashMap<>();
        map.put("ids",ids);
        map.put("onSaleTime",new Date());
        petMapper.onSale(map);
    }

    @Override
    public void offSale(List<Long> ids) {
        Map<String,Object> map=new HashMap<>();
        map.put("ids",ids);
        map.put("offSaleTime",new Date());
        petMapper.offSale(map);
    }

    @Override
    public Pet queryByIdDetail(Long id) {
        return petMapper.loadByIdDetail(id);
    }
}
